package org.dftproject.genesis.ui.figures;

import java.util.Iterator;
import java.util.List;

import org.eclipse.draw2d.Figure;
import org.eclipse.draw2d.Graphics;
import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.ToolbarLayout;
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.swt.graphics.Color;

public class LinedContainer extends Figure {
	
	private final static Color borderColor = new Color(null, 0xAA, 0xAA, 0xAA);
	
	public LinedContainer() {
		ToolbarLayout layout = new ToolbarLayout(false);
		layout.setSpacing(1);
		setLayoutManager(layout);
	}
	
	@Override
	public void paintFigure(Graphics graphics) {
		super.paintFigure(graphics);
		
		graphics.setForegroundColor(borderColor);
	
		int left = getClientArea().x;
		int right = getClientArea().right();
		
		@SuppressWarnings("unchecked")
		List<IFigure> children = getChildren();
		Iterator<IFigure> iter = children.iterator();
		while (iter.hasNext()) {
			IFigure child = iter.next();
			if (iter.hasNext()) {
				Rectangle bounds = child.getBounds();
				graphics.drawLine(left, bounds.bottom(), right, bounds.bottom());
			}
		}
	}

}
